using UnityEngine;
using UnityEngine.UI;

namespace MaterialUI
{
	[ExecuteInEditMode]
	[AddComponentMenu("MaterialUI/Toggles/Material Checkbox", 100)]
	public class MaterialCheckbox : ToggleBase
	{
		[SerializeField]
		private Graphic m_CheckImage;

		[SerializeField]
		private Graphic m_FrameImage;

		private RectTransform m_CheckRectTransform;

		private float m_CurrentCheckSize;

		private Color m_CurrentFrameColor;

		public Graphic checkImage
		{
			get
			{
				return m_CheckImage;
			}
			set
			{
				m_CheckImage = value;
			}
		}

		public Graphic frameImage
		{
			get
			{
				return m_FrameImage;
			}
			set
			{
				m_FrameImage = value;
			}
		}

		public RectTransform checkRectTransform
		{
			get
			{
				if (m_CheckRectTransform == null && m_CheckImage != null)
				{
					m_CheckRectTransform = (RectTransform)m_CheckImage.transform;
				}
				return m_CheckRectTransform;
			}
		}

		protected override void OnEnable()
		{
			base.OnEnable();
			m_CheckRectTransform = checkImage.GetComponent<RectTransform>();
		}

		public override void TurnOn()
		{
			Vector2 sizeDelta = checkImage.rectTransform.sizeDelta;
			m_CurrentCheckSize = sizeDelta.x;
			m_CurrentColor = checkImage.color;
			m_CurrentFrameColor = frameImage.color;
			base.TurnOn();
		}

		public override void TurnOnInstant()
		{
			base.TurnOnInstant();
			if (m_Toggle.interactable)
			{
				AnimOnComplete();
			}
			checkRectTransform.sizeDelta = new Vector2(24f, 24f);
		}

		public override void TurnOff()
		{
			Vector2 sizeDelta = checkImage.rectTransform.sizeDelta;
			m_CurrentCheckSize = sizeDelta.x;
			m_CurrentColor = checkImage.color;
			m_CurrentFrameColor = frameImage.color;
			base.TurnOff();
		}

		public override void TurnOffInstant()
		{
			base.TurnOffInstant();
			if (m_Toggle.interactable)
			{
				AnimOffComplete();
			}
			checkRectTransform.sizeDelta = Vector2.zero;
		}

		public override void Enable()
		{
			base.Enable();
			if (m_Toggle.isOn)
			{
				AnimOnComplete();
			}
			else
			{
				AnimOffComplete();
			}
		}

		public override void Disable()
		{
			base.Disable();
			checkImage.color = base.disabledColor;
			frameImage.color = base.disabledColor;
		}

		public override void AnimOn()
		{
			base.AnimOn();
			checkImage.color = Tween.QuintOut(m_CurrentColor, base.onColor, m_AnimDeltaTime, base.animationDuration);
			frameImage.color = Tween.QuintOut(m_CurrentFrameColor, base.onColor, m_AnimDeltaTime, base.animationDuration);
			float num = Tween.QuintOut(m_CurrentCheckSize, 24f, m_AnimDeltaTime, base.animationDuration);
			checkRectTransform.sizeDelta = new Vector2(num, num);
		}

		public override void AnimOnComplete()
		{
			base.AnimOnComplete();
			checkImage.color = base.onColor;
			frameImage.color = base.onColor;
			checkRectTransform.sizeDelta = new Vector2(24f, 24f);
		}

		public override void AnimOff()
		{
			base.AnimOff();
			checkImage.color = Tween.QuintOut(m_CurrentColor, base.offColor, m_AnimDeltaTime, base.animationDuration);
			frameImage.color = Tween.QuintOut(m_CurrentFrameColor, base.offColor, m_AnimDeltaTime, base.animationDuration);
			float num = Tween.QuintOut(m_CurrentCheckSize, 0f, m_AnimDeltaTime, base.animationDuration);
			checkRectTransform.sizeDelta = new Vector2(num, num);
		}

		public override void AnimOffComplete()
		{
			base.AnimOffComplete();
			checkImage.color = base.offColor;
			frameImage.color = base.offColor;
			checkRectTransform.sizeDelta = new Vector2(0f, 0f);
		}
	}
}
